<!-- 车库详情 -->

<template>
  <EasyModal v-model="model" v-bind="MAP.MODEL_PROPS">
    <DeviceAlarm :id="one.alarmId" :content="one.alarmContent" />

    <div class="Secure-DetailParking marginBottom">
      <MajorTitle :title="one.entranceName" />

      <ParamTab :dict="tabDict" class="marginBottom" />

      <MyRecord v-if="param.tab === 'record'" />

      <div v-else-if="param.tab">
        <MyBase />
        <MyDevice />
      </div>
    </div>
  </EasyModal>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import store from './store'
import mixDetail from '@admin/components/detail/mixDetail'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'DetailParking',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixStore(store), mixDetail],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 页签字典
     */
    tabDict() {
      const { roadway = [] } = this.one
      const roadwayDict = roadway.map(({ id, roadwayName }) => [id, roadwayName])
      return [...roadwayDict, ['record', '通行记录']]
    },
  },

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听 ID
     */
    id() {
      this.param.tab = ''
      this.roadway_setOne()
      this.record_setList()
    },

    /**
     * 监听单项就绪
     */
    readyOne(ready) {
      if (ready) {
        const { param, one } = this
        param.tab = CORE.isEmpty(one.roadway) ? 'record' : one.roadway[0].id
      }
    },

    /**
     * 监听页签
     */
    'param.tab'(tab) {
      if (tab === 'record') this.record_startList()
      else this.roadway_startOne()
    },
  },
}
</script>

<style lang="scss">
@import './index.scss';
</style>
